import i18n from '@/i18n'

// 国际化的时间格式化函数
export function formatDuration(seconds: number): string {
  const t = i18n.global.t
  
  if (seconds < 60) {
    return `${seconds}${t('time.second')}`
  } else if (seconds < 3600) {
    const minutes = Math.floor(seconds / 60)
    const remainingSeconds = seconds % 60
    return `${minutes}${t('time.minute')}${remainingSeconds}${t('time.second')}`
  } else {
    const hours = Math.floor(seconds / 3600)
    const remainingMinutes = Math.floor((seconds % 3600) / 60)
    return `${hours}${t('time.hour')}${remainingMinutes}${t('time.minute')}`
  }
}

// 字节格式化函数
export function formatBytes(bytes: number): string {
  if (bytes === 0) return '0 B'
  
  const k = 1024
  const sizes = ['B', 'KB', 'MB', 'GB', 'TB']
  const i = Math.floor(Math.log(bytes) / Math.log(k))
  
  return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i]
} 